Ext.define('App.reportconfiguration.chartconfiguration.model.SeriesModel', {
    extend: 'Extend.data.BaseModel',
    fields: [
        {name: 'type'},
        {name: 'xField'},
        {name: 'yFields'},
        {name: 'axis'},
        {name: 'stacked'},
        {name: 'percent'},
        {name: 'fill'},
        {
            name: 'yFieldsArray',
            calculate: function (data) {
                var yFields = data.yFields;
                if (Ext.isEmpty(yFields)) {
                    return [];
                }
                if (Ext.isArray(yFields)) {
                    return yFields;
                }
                return yFields.split(', ');
            }
        }
    ],
    validators: {
        type: 'presence',
        xField: 'presence',
        yFields: 'SeriesPresence',
        axis: {type: 'SeriesPresence'}
    }
});
//Y轴数据及Y轴字段验证器：如果类型为饼图时，Y轴数据及Y轴允许为空，否则不允许为空
Ext.define('Ext.data.validator.SeriesPresence', {
    extend: 'Ext.data.validator.Validator',
    alias: 'data.validator.SeriesPresence',
    type: 'SeriesPresence',
    config: {
        message: 'Must be present',
        allowEmpty: false
    },
    validate: function (value, record) {
        if (record.get('type') == 'pie' || record.get("type") == 'pie3d') {
            return true;
        }
        var me = this;
        var valid = !(Ext.isEmpty(value));
        if (valid && !this.getAllowEmpty()) {
            valid = !(value === '');
        }
        return valid ? true : this.getMessage();
    }
});